<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>工程施工实时监控系统</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">


    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <!--<link rel="stylesheet" href="${pageContext.request.contextPath}/${pageContext.request.contextPath}/${pageContext.request.contextPath}/plugins/timepicker/bootstrap-timepicker.min.css">-->

    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>


    <!--<script src="${pageContext.request.contextPath}/${pageContext.request.contextPath}/${pageContext.request.contextPath}/plugins/timepicker/bootstrap-timepicker.min.js"></script>-->

    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/morris/morris.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/select2/select2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/layui/css/layui.css" media="all">
    <style>
        .content {
            padding-bottom: 25px;
        }

        /*使layui数据表格的checkbox居中*/
        .layui-table-cell .layui-form-checkbox[lay-skin="primary"] {
            top: 50%;
            transform: translateY(-50%);
        }

        .layui-form-item {
            height: 40px;
        }

        .layui-form-label {
            width: 100px;
        }

        .mylabel {
            font: 14px Helvetica Neue, Helvetica, PingFang SC, Tahoma, Arial, sans-serif;
            width: 50px;
        }
    </style>
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper">
    <security:authentication property="principal.id" var="id"
    ></security:authentication>
    <!-- 页面头部 -->
    <jsp:include page="header.jsp"></jsp:include>
    <!-- 页面头部 /-->

    <!-- 导航侧栏 -->
    <jsp:include page="aside.jsp"></jsp:include>
    <!-- 导航侧栏 /-->

    <!-- 内容区域 -->
    <!-- @@master = admin-layout.html-->
    <!-- @@block = content -->

    <div class="content-wrapper">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1>
                设备管理
                <%--<small>数据列表</small>--%>
            </h1>
            <ol class="breadcrumb">
                <li><a href="${pageContext.request.contextPath}/pages/main.jsp"><i class="fa fa-dashboard"></i> 首页</a>
                </li>
                <li class="active">设备管理</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!-- .box-body -->
            <div class="box box-primary">
                <%--新增用户表单--%>
                <div class="site-text" style="margin: 5%; display: none" id="addDeviceWindow" target="test123">
                    <form class="layui-form" id="book" method="post" lay-filter="example">
                        <div class="layui-form-item">
                            <label class="layui-form-label">设备名称</label>
                            <div class="layui-input-block">
                                <input type="text" id="devName" name="devName" lay-verify="required"
                                       lay-filter="devName" autocomplete="off" placeholder="请输入设备名称"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">设备编号</label>
                            <div class="layui-input-block">
                                <input type="text" id="devNum" name="devNum" lay-verify="required"
                                       lay-filter="devNum" autocomplete="off" placeholder="请输入设备编号"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">机器编号</label>
                            <div class="layui-input-block">
                                <input type="text" id="machineNum" name="machineNum" lay-verify="required"
                                       lay-filter="machineNum" autocomplete="off" placeholder="请输入机器编号"
                                       class="layui-input">
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">所属项目</label>
                            <div class="layui-input-block">
                                <select name="projectVal" id="projectVal" lay-filter="projectVal" lay-verify="required">
                                    <option value="">请选择项目</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">所属标段</label>
                            <div class="layui-input-block" id="sectionVal">
                                <select name="section_id" id="section_id" lay-filter="section_id" lay-verify="required">
                                    <option value="">请选择标段</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">设备类型</label>
                            <div class="layui-input-block">
                                <select name="state" id="devCode" lay-filter="devCode">
                                    <option value="0">双头搅拌机</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">设备厂家</label>
                            <div class="layui-input-block">
                                <input type="text" id="manufacturers" name="manufacturers" lay-verify="required"
                                       lay-filter="manufacturers" autocomplete="off" placeholder="请输入设备厂家"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序ID</label>
                            <div class="layui-input-block">
                                <input type="text" id="orderBy" name="orderBy" lay-verify="required"
                                       autocomplete="off"
                                       placeholder="请输入排序ID" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">是否启用</label>
                            <div class="layui-input-block">
                                <select name="state" id="state" lay-filter="state">
                                    <option value="0">未激活</option>
                                    <option value="1">已离线</option>
                                    <option value="2">已离场</option>
                                    <option value="3">运行中</option>
                                    <option value="4">故障中</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">桩孔数量</label>
                            <div class="layui-input-block">
                                <input type="text" id="devTotal" name="devTotal"
                                       autocomplete="off" lay-verify="required"
                                       class="layui-input">
                            </div>
                        </div>

                        <!--  <div class="layui-form-item">
                           <div class="layui-input-block">
                             <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                           </div>
                         </div> -->
                    </form>
                </div>
                <%--end新增用户表单--%>


            </div>
            <div class="demoTable">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto" id="resetForm">

                    <div class="layui-inline">
                        <select name="projectId" id="projectId" lay-filter="projectId">
                            <option value="">请选择项目</option>
                        </select>
                    </div>
                    <div class="layui-inline" id="sectionSel">
                        <select name="sectionId" id="sectionId" lay-filter="sectionId">
                            <option value="">请选择标段</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <input class="layui-input" autocomplete="off" name="name" id="name"
                               placeholder="请输入设备编号">
                    </div>

                    <button class="layui-btn" data-type="reload">搜索</button>
                    <button class="layui-btn" id="reset">重置</button>
                    <button class="layui-btn" id="addDevice" style="float:right">添加设备</button>


                    <%--</div>--%>
                </div>
            </div>
            <table class="layui-hide" id="deviceTable" lay-filter="deviceTable">

            </table>

            <script type="text/html" id="toolbarDemo">

                <%--<button class=" layui-icon-cols" lay-event="refresh">刷新</button>--%>
            </script>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
            <script src="${pageContext.request.contextPath}/plugins/layui/layui.js" charset="utf-8"></script>
            <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
        </section>
        <!-- 正文区域 /-->

    </div>
    <!-- @@close -->
    <!-- 内容区域 /-->


</div>


<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/raphael/raphael-min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/morris/morris.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="${pageContext.request.contextPath}/plugins/knob/jquery.knob.js"></script>
<script src="${pageContext.request.contextPath}/plugins/daterangepicker/moment.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.js"></script>
<script src="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${pageContext.request.contextPath}/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/fastclick/fastclick.js"></script>
<script src="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/adminLTE/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/treeTable/jquery.treetable.js"></script>
<script src="${pageContext.request.contextPath}/plugins/select2/select2.full.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-markdown/js/markdown.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-markdown/js/to-markdown.js"></script>
<script src="${pageContext.request.contextPath}/plugins/ckeditor/ckeditor.js"></script>
<script src="${pageContext.request.contextPath}/plugins/input-mask/jquery.inputmask.js"></script>
<script src="${pageContext.request.contextPath}/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="${pageContext.request.contextPath}/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="${pageContext.request.contextPath}/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/chartjs/Chart.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/flot/jquery.flot.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/flot/jquery.flot.resize.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/flot/jquery.flot.pie.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/flot/jquery.flot.categories.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/ionslider/ion.rangeSlider.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-slider/bootstrap-slider.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script>
    //主体表格
    layui.use(['table', 'layer', 'form', 'element'], function () {
        var table = layui.table;
        var form = layui.form;
        var element = layui.element;
        var id = "${id}";
        table.render({
            elem: '#deviceTable'
            , url: '/deviceManage/findAll.do'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-refresh'
            }]
            , method: 'post'
            , skin: 'nob'//样式格式

            , where: {
                userId: id
            }
            // , totalRow: true 合计行
            , title: '设备列表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'},
                {title: '序号', align: 'center', type: 'numbers'}
                , {field: 'devName', title: '设备名称', width: '10%', edit: 'text', align: "center"}
                , {field: 'devNum', title: '设备编号', width: '11%', edit: 'text', align: "center"}
                , {field: 'machineNum', title: '机器编号', width: '6%', edit: 'text', align: "center"}
                , {
                    field: 'projectName',
                    title: '所属项目',
                    width: '9%',
                    edit: 'text',
                    align: "center",
                    templet: function (item) {
                        //如果为null,这不显示
                        if (!item.section.project.projectName) {
                            return "";
                        }
                        //如果有值则显示
                        return item.section.project.projectName;
                    }

                }
                , {
                    field: 'sectionName',
                    title: '所属标段',
                    width: '14%',
                    edit: 'text',
                    align: "center",
                    templet: function (item) {
                        //如果为null,这不显示
                        if (item.section.sectionName == null) {
                            return "";
                        }
                        //如果有值则显示
                        return item.section.sectionName;
                    }
                }
                , {field: 'manufacturers', title: '设备厂家', width: '15%', edit: 'text', align: "center"}
                , {
                    field: 'devCode',
                    title: '设备类型',
                    width: '7%',
                    edit: 'text',
                    align: "center",
                    templet: function (item) {
                        if (item.devCode == '0') {
                            return "双头搅拌机";
                        }
                    }
                }
                , {field: 'devTotal', title: '桩孔数量', width: '6%', edit: 'text', align: "center"}
                , {field: 'orderBy', title: '排序', width: '4%', edit: 'text', align: "center"}
                , {
                    field: 'state', title: '状态', width: '5%', edit: 'text', align: "center", templet: function (item) {
                        if (item.state == '0') {
                            return "未激活";
                        } else if (item.state == '1') {
                            return "已离线";
                        } else if (item.state == '2') {
                            return "已离场";
                        } else if (item.state == '3') {
                            return "运行中";
                        } else if (item.state == '4') {
                            return "故障中";
                        }
                    }
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: '8%'}
            ]],
            done: function (res, curr, count) {
                $("table").css("width", "100%");
                //这里设置表格的宽度为100%
            },
            page: true
            ,
            id: 'testReload'
        });
        //条件查询重载表格
        var $ = layui.$, active = {
            reload: function () {
                var sectionId = $("#sectionId");
                var name = $('#name');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        // key: {
                        devNum: name.val(),
                        sectionId: sectionId.val()

                        // }
                    }
                }, 'data');
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //头工具栏事件
        table.on('toolbar(deviceTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    $(".layui-laypage-btn").click();
                    break;
            }
        });
        //重置
        $('#reset').on('click', function () {
            $(':input', '#resetForm')
                .not(":button", ":reset", "hidden", "submit")
                .val("")
                .removeAttr("checked")
                .removeAttr("selected");
            // $.ajax({
            //     type: "get",
            //     url: "/section/sectionGroupName.do",
            //     data: {
            //         projectId: $("#projectId").val()
            //     },
            //     success: function (Data) {
            //         // console.log(Data)
            //         var section = $("#sectionSel");
            //         var html = "";
            //         html += '<select name="sectionId" id="sectionId" lay-filter="sectionId">';
            //         html += '<option value="">' + "请选择标段" + '</option>';
            //         for (var i = 0; i < Data.length; i++) {
            //             // console.log(Data[1])
            //             html += '<option value="' + Data[i].id + '">' + Data[i].sectionName + '</option>';
            //         }
            //         html += '</select>';
            //         section.html(html);
            //         form.render('select');
            //     }
            // });

            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    devNum: "",
                    sectionId: ""
                }
            }, 'data');
        });

        //搜索框下拉框联动
        form.on('select(projectId)', function (obj) {
            $.ajax({
                type: "get",
                url: "/section/sectionGroupName.do",
                data: {
                    projectId: obj.value,
                    userId: id
                },
                success: function (Data) {
                    // console.log(Data)
                    var section = $("#sectionSel");
                    var html = "";
                    html += '<select name="sectionId" id="sectionId" lay-filter="sectionId">';
                    html += '<option value="" >请选择标段</option>';

                    for (var i = 0; i < Data.length; i++) {
                        // console.log(Data[1])
                        html += '<option value="' + Data[i].id + '">' + Data[i].sectionName + '</option>';
                    }
                    html += '</select>';
                    section.html(html);
                    form.render('select');
                }
            });
        });
        //添加页面下拉框联动
        form.on('select(projectVal)', function (obj) {
            $.ajax({
                type: "get",
                url: "/section/sectionGroupName.do",
                data: {
                    projectId: obj.value,
                    userId: id
                },
                success: function (Data) {
                    var section = $("#sectionVal");
                    var html = "";
                    html += '<select name="section_id" id="section_id" lay-filter="section_id">';
                    html += '<option value="" >请选择标段</option>';
                    for (var i = 0; i < Data.length; i++) {
                        html += '<option value="' + Data[i].id + '">' + Data[i].sectionName + '</option>';
                    }
                    html += '</select>';
                    section.html(html);
                    form.render('select');
                }
            });
        });


        //添加标段
        $("#addDevice").click(function () {
            layer.open({
                type: 1,
                title: "标段基本信息",
                area: ['30%', '70%'],//窗口大小
                btn: ['确定', '取消'],//按钮
                content: $("#addDeviceWindow"),//对应表单
                success: function (layero) {
                    // 解决按enter键重复弹窗问题
                    $(':focus').blur();
                    // 添加form标识
                    layero.addClass('layui-form');
                    // 将保存按钮改变成提交按钮
                    layero.find('.layui-layer-btn0').attr({
                        'lay-filter': 'book',
                        'lay-submit': ''
                    });

                    // 表单验证
                    /*    form.verify({
                            username : function(value, item) {
                                if (!new RegExp("^[a-zA-Z0-9_|\u4e00-\u9fa5\]{2,10}$")
                                    .test(value)) {
                                    return '角色名必须为2-10位且不能有特殊字符';
                                }
                            },
                        });*/
                    // 刷新渲染(否则开关按钮会不显示)
                    form.render();
                },
                yes: function (index, layero) {
                    // console.log($('#compellation').val());
                    // 监听提交按钮
                    form.on('submit(book)', function (data) {
                        $.ajax({
                            type: "post",
                            url: "/deviceManage/save.do",
                            data: {
                                devName: $('#devName').val(),
                                devNum: $('#devNum').val(),
                                machineNum: $('#machineNum').val(),
                                devCode: $('#devCode').val(),
                                manufacturers: $('#manufacturers').val(),
                                orderBy: $('#orderBy').val(),
                                state: $('#state').val(),
                                devTotal: $('#devTotal').val(),
                                section_id: $('#section_id').val()
                            },
                            success: function (Data) {
                                if (Data.result) {
                                    layer.alert(Data.msg, {icon: 1, title: '提示'}, function (i) {
                                        layer.close(i);
                                        layer.close(index);//关闭弹出层
                                        $("#book")[0].reset()//重置form
                                    })
                                    table.reload('testReload', {//重载表格
                                        page: {
                                            curr: 1
                                        }
                                    })
                                } else {
                                    layer.msg("添加失败")
                                }
                            }, error: function () {
                                layer.alert("服务器错误", {icon: 1, title: '提示'}, function (i) {
                                    layer.close(i);
                                    layer.close(index);//关闭弹出层
                                    $("#book")[0].reset()//重置form
                                })
                            }
                        })
                    });
                }
            });
        })

        //监听行工具事件
        table.on('tool(deviceTable)', function (obj) {
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        type: "post",
                        url: "/deviceManage/del.do",
                        data: {
                            id: obj.data.id
                        },
                        success: function (Data) {
                            if (Data.result) {
                                layer.msg("删除成功");
                                obj.del();//删除当前行
                                layer.close(index);//关闭弹出层
                            } else {
                                layer.msg("删除失败");
                                layer.close(index);//关闭弹出层

                            }
                        }, error: function () {
                            layer.msg("删除失败");
                            layer.close(index);//关闭弹出层
                        }
                    })
                });

            } else if (obj.event === 'edit') {
                layer.open({
                        type: 1,
                        title: "设备基本信息",
                        area: ['30%', '70%'],//窗口大小
                        btn: ['确定', '取消'],//按钮
                        content: $("#addDeviceWindow"),//对应表单
                        success: function (index, layero) {
                            $('#devName').val(obj.data.devName);
                            $('#devNum').val(obj.data.devNum);
                            $('#machineNum').val(obj.data.machineNum);
                            $('#section_id').val(obj.data.section_id);
                            // $('#projectVal').val(obj.data.section.project_id);
                            $('#devCode').val(obj.data.devCode);
                            $('#manufacturers').val(obj.data.manufacturers);
                            $('#orderBy').val(obj.data.orderBy);
                            $('#devTotal').val(obj.data.devTotal);
                            $('#state').val(obj.data.state);
                            form.render('select');//刷新select
                        }, yes: function (index, layero) {
                            // 监听提交按钮
                            $.ajax({
                                type: "post",
                                url: "/deviceManage/update.do",
                                data: {
                                    id: obj.data.id,
                                    devName: $('#devName').val(),
                                    devNum: $('#devNum').val(),
                                    section_id: $('#section_id').val(),
                                    machineNum: $('#machineNum').val(),
                                    devCode: $('#devCode').val(),
                                    manufacturers: $('#manufacturers').val(),
                                    orderBy: $('#orderBy').val(),
                                    devTotal: $('#devTotal').val(),
                                    state: $('#state').val()
                                },
                                success: function (Data) {
                                    if (Data.result) {
                                        layer.alert(Data.msg, {icon: 1, title: '提示'}, function (i) {
                                            layer.close(i);
                                            layer.close(index);//关闭弹出层
                                            $("#book")[0].reset()//重置form
                                        })
                                        table.reload('testReload', {//重载表格
                                            page: {
                                                curr: 1
                                            }
                                        })
                                    } else {
                                        layer.alert("修改失败", {icon: 1, title: '提示'}, function (i) {
                                            layer.close(i);
                                            layer.close(index);//关闭弹出层
                                        })
                                    }
                                }, error: function () {
                                    layer.alert("服务器错误", {icon: 1, title: '提示'}, function (i) {
                                        layer.close(i);
                                        layer.close(index);//关闭弹出层
                                    })
                                }
                            })
                        }, end: function () {
                            $("#book")[0].reset()//重置form
                        }
                    }
                )
            }
        });
    });


    $(document).ready(function () {
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });

    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }

    layui.use('form', function () {
        var form = layui.form;
        var id = "${id}";
        var arr = [];
        //获取标段列表
        $.ajax({
            type: "get",
            url: "/section/sectionGroupNameByUserId.do",
            data: {
                userId: id
            },
            success: function (Data) {
                // console.log(Data)
                var section = $("#sectionId");
                var sectionVal = $("#section_id");

                var html = "";

                for (var i = 0; i < Data.length; i++) {
                    html += '<option value="' + Data[i].id + '">' + Data[i].sectionName + '</option>';
                    console.log(Data[i].project_id)
                    arr.push(Data[i].project_id)
                }
                section.append(html);
                sectionVal.append(html);
                form.render('select');
                //获取项目列表
                $.ajax({
                    type: "get",
                    url: "/project/projectGroupName.do",
                    traditional: true,//这条必须加上，否则传不了数组
                    data: {
                        projectIds: arr
                    },
                    success: function (Data) {
                        // console.log(Data)
                        var project = $("#projectId");
                        var projectVal = $("#projectVal");
                        var html = "";
                        for (var i = 0; i < Data.length; i++) {
                            html += '<option value="' + Data[i].id + '">' + Data[i].projectName + '</option>';
                        }
                        project.append(html);
                        projectVal.append(html);
                        form.render('select');
                    }
                });
            }
        });


    })


    $(document).ready(function () {

        // 激活导航位置
        setSidebarActive("admin-datalist");

        // 列表按钮
        $("#dataList td input[type='checkbox']").iCheck({
            checkboxClass: 'icheckbox_square-blue',
            increaseArea: '20%'
        });
        // 全选操作
        $("#selall").click(function () {
            var clicks = $(this).is(':checked');
            if (!clicks) {
                $("#dataList td input[type='checkbox']").iCheck("uncheck");
            } else {
                $("#dataList td input[type='checkbox']").iCheck("check");
            }
            $(this).data("clicks", !clicks);
        });

    });

</script>
</body>

</html>
